<?php
/*
 * employe/add.phtml
 */
?>
<?php

use RHX\Helper\RHDateTime;
use RHX\Helper\Number;
use RHX\Model\Manager\FileManager;
?>


<?php
$title = 'Nouvel Employé';
$this->headTitle($title);

// Variables
$site = $this->site;

$etatCivil	 = array(0	 => 'Monsieur', 1	 => 'Monsieur', 2	 => 'Madame', 3	 => 'Mademoiselle');
//$typeContrat	 = array(
//    '0'	 => 'Contrat à Durée Déterminée (CDD)',
//    '1'	 => 'Contrat à Durée Déterminée (CDD)',
//    '2'	 => 'Contrat à Durée Indéterminée (CDI)',
//);
$typeContrat	 = $this->contratTypes;
$situation	 = array(
    '0'	 => 'Célibataire',
    '1'	 => 'Célibataire',
    '2'	 => 'Marié(e)',
    '3'	 => 'Divorcé(e)',
    '4'	 => 'Veuf(ve)',
);
$niveau		 = array();
$echelon	 = array();
for ($i = 1; $i < 6; $i++) {
    if ($i < 5) {
	$echelon["$i"] = "Echelon $i";
    }
    $niveau["$i"] = "Niveau " . Number::getRomanNumber($i);
}

$dayWeek = array(1 => 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche');

?>

<div class="content-head">
    <?php $name = ''; ?>
    <h3><?php echo $title; ?></h3>
    <!--div class="toolbar">
        <button class='btn btn-inverse' onclick="location.href = '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'index', 'id'		 => $site->id, 'other1'	 => 1)) ?>';">Annuler et revenir à la liste des employés du Site <b><?php echo $site->libelle ?></b></button>
    </div-->
</div>
<div class="content-body empl-border">
    <div class="empl-full bleu empl-title">Etat Civil : <a href="#" id="etatcivil" data-type="select"><?php echo $etatCivil[1] ?></a></div>

    <div class="empl-top">
        <div class="empl-matricule saumon empl-title">Matricule : <a href="#" onclick="return false;">#</a></div>
        <div class="empl-site marron empl-title">
            Site Employeur : <a href="#" id="site" data-type="select"><?php echo $site->libelle; ?></a>
        </div>
    </div>

    <div class="empl-left">
        <div class="empl-group">
            <div class="empl-photo">
		<a href="#" id="photo-upload" title="Changer la photo" style="width: 100%; height: 100%;">
		    <img id="photo" src="<?php echo $this->basePath() . '/img/rhx/user-192x200.png' ?>" width="200" height="250">
		</a>
	    </div>
            <!--div class="empl-full violet" style="text-align: center;">
		CV : <span id="cv_"></span>
		<a href="#" id="cv-upload" class="btn btn-info btn-small">Télécharger</a>
	    </div-->
            
            <div class='empl-full violet' style="text-align: center;">                    
                CV : 
                <?php $flagFile  = FileManager::EMPLOYE_CV_FILE ;
                      $fileManager->setFlag($flagFile);
                ?>

                <?php $idLibelleFIle    = $fileManager->getFlag(). '_libelle' ;
                      $idBtnUplFile     = $fileManager->getFlag() . '-upload'; 
                ?>

                <span id="<?php echo $idLibelleFIle; ?>"></span>
                <a href="#" id="<?php echo $idBtnUplFile ; ?>" class="btn btn-info btn-small">Télécharger</a>
            </div>
            
            <div class="empl-full saumon" style="text-align: center;">
		Code Caisse TC POS<br>
		<a href="#" id="code_caisse" data-type="text"></a>
	    </div>
        </div>
    </div>

    <div class="empl-center">

        <div class='empl-group'>
            <div class='empl-full saumon2'>
                Nom d'usage : <a href="#" id="nom" class="uppercase" data-type="text"></a>
            </div>
            <div class='empl-full saumon2'>
                Nom de jeune Fille : <a href="#" class="uppercase" id="nom2" data-type="text"></a>
            </div>
            <div class='empl-full saumon2'>
                Prénom : <a href="#" id="prenom" class="capitalize" data-type="text"></a>
            </div>
        </div>

        <div class="empl-group">
            <div class="empl-full gris">Adresse 1 : <a href="#" id="adresse1" data-type="text"></a></div>
            <div class="empl-half gris">CP : <a href="#" id="cp1" data-type="text"></a></div>
            <div class="empl-half gris">Ville : <a href="#" id="ville1" data-type="text"></a></div>
            <div class="empl-full gris">Adresse 2 : <a href="#" id="adresse2" data-type="text"></a></div>
            <div class="empl-half gris">CP : <a href="#" id="cp2" data-type="text"></a></div>
            <div class="empl-half gris">Ville : <a href="#" id="ville2" data-type="text"></a></div>
            <div class="empl-half gris">Téléphone : <a href="#" id="num_mobile" data-type="text"></a></div>
            <div class="empl-half gris">E-mail : <a href="#" id="email" data-type="text"></a></div>
        </div>

        <div class="empl-group">
            <div class="empl-full beige">
                Numéro d'immatriculation CPAM : <a href="#" id="num_cpam" data-type="text"></a>
            </div>
            <div class="empl-full beige">
                Situation Familiale : <a href="#" id="situation_familiale" data-type="select"><?php echo $situation[1]; ?></a>
            </div>
            <div class="empl-full beige">
                Nombre d'enfant : <a href="#" id="nombre_enfant" data-type="text">0</a>
            </div>
            <div class="empl-full beige">
                Numéro d'immatriculation Pole Emploi : <a href="#" id="num_pole_emploi" data-type="text"></a>
            </div>
        </div>

        <div class='empl-group'>
            <div class='empl-half gris'>
                Mutuelle : <a href="#" id="mutuelle" data-type="select"></a>
            </div>
            <div class='empl-half gris-beige'>
                Titre Transport : <a href="#" id="titre_transport" data-type="select"></a>
            </div>
            <div class='empl-half gris'>
                Date d'effet : <a class="rhdatetime" href="#" id="date_effet" data-type="combodate">Aucun</a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="date_effet" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div>
            <div class='empl-half gris-beige'>
                Véhicule de fonction : <a href="#" id="vehicule_fonction"></a>
            </div>
            <div class='empl-half' style='border: none; margin-right: 2px'></div>
            <div class='empl-half gris-beige'>
                Immatriculation du véhicule : <a href="#" id="immatriculation" data-type="text"></a>
            </div>
            <div class='empl-half gris'>
                Date visite médicale : <a class="rhdatetime" href="#" id="date_visite" data-type="combodate">Aucun</a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="date_visite" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div>
            <div class='empl-half gris-beige'>
                Numéro de permis : <a class="rhdatetime" href="#" id="num_permis" data-type="text"></a>
            </div>
        </div>
    </div>
    <div class="empl-right">

        <div class='empl-group'>
            <div class='empl-full gris-beige'>
                Date de naissance : <a class="rhdatetime" href="#" id='date_naissance' data-type="combodate">Aucun</a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="date_naissance" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div>
            <div class='empl-full gris-beige'>
                Lieu de naissance : <a href="#" id="lieu_naissance" data-type="textarea"></a>
            </div>
            <div class='empl-full gris-beige'>
                Pays de naissance : <a href="#" id="pays_naissance" data-type="text"></a>
            </div>
            <div class='empl-full gris-beige'>
                Nationalité : <a href="#" id="nationalite" data-type="select"></a>
            </div>
        </div>

        <div class='empl-group'>
            <div class='empl-full saumon'>
                Type Titre de Séjour : <a href="#" id="titre_sejour" data-type="select">Aucun</a>
            </div>
            
            <div class='empl-full saumon' >                    
                N° Titre de Séjour : <a href="#" id="num_titre_sejour" data-type="text"></a>
                
                <div style='margin-top: 4px; text-align: center;'>
                    <?php $flagFile  = FileManager::EMPLOYE_SEJOUR_NUM_FILE ;
                          $fileManager->setFlag($flagFile);
                    ?>

                    <?php $idLibelleFIle    = $fileManager->getFlag(). '_libelle' ;
                          $idBtnUplFile     = $fileManager->getFlag() . '-upload'; 
                    ?>

                    <span id="<?php echo $idLibelleFIle; ?>"></span>
                    <a href="#" id="<?php echo $idBtnUplFile ; ?>" class="btn btn-info btn-small">Télécharger</a>
                </div>
            </div>
            
            <div class='empl-full saumon' >
                Fin de validité Titre Séjour : <a class="rhdatetime" href="#" id="date_fin_validite_sejour" data-type="combodate">Aucun</a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="date_fin_validite_sejour" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div>
        </div>

        <div class='empl-group'>
            <div class="empl-full bleu-2" style="color: whitesmoke; text-transform: uppercase; text-align: center;">RIB</div>
            
            <div class='empl-full gris-beige'>
                IBAN : <a href="#" id="rib_iban" data-name="rib_iban"  data-type="text"></a>
            </div>
            <div class='empl-full gris-beige'>
                BIC : <a href="#" id="rib_bic" data-name="rib_bic" data-type="text"> </a>
            </div>
            
           <div class='empl-full gris' >                    
                Fichier RIB : 
                <?php $flagFile  = FileManager::EMPLOYE_RIB_FILE ;
                      $fileManager->setFlag($flagFile);
                ?>

                <?php $idLibelleFIle    = $fileManager->getFlag(). '_libelle' ;
                      $idBtnUplFile     = $fileManager->getFlag() . '-upload'; 
                ?>

                <span id="<?php echo $idLibelleFIle; ?>"></span>
                <a href="#" id="<?php echo $idBtnUplFile ; ?>" class="btn btn-info btn-small">Télécharger</a>
            </div>
        </div>
        <div class='empl-group'>
            
        </div>

        <!-- DIPLOMES ET FORMATIONS -->
        <div class='empl-group'>
	    <!-- DIPLOMES -->
	    <div class="empl-full bleu-navy" style="color: whitesmoke; text-transform: uppercase; text-align: center;">Diplômes</div>
	    <div id="diplomes"></div>
	    <div id="diplome-none" class='empl-full violet'>Aucun Diplôme</div>
	    <div class="empl-full">&nbsp;<button class="btn btn-info add-diplome" style="float: right;">Ajouter un Diplôme</button></div>

	    <!-- FORMATIONS -->
	    <div class="empl-full bleu-navy" style="color: whitesmoke; text-transform: uppercase; text-align: center;">Formations</div>
	    <div id="formations-list"></div>
	    <div id="formation-none" class='empl-full vert-olive'>Aucune Formation Continue</div>
	    <div class="empl-full">&nbsp;<button class="btn btn-success add-formation" style="float: right;">Ajouter une Formation</button></div>
        </div>

	<!--    </div>-->

    </div>

    <div style="clear: both"></div>

</div>

<!-- Contrat -->
<?php
//
?>
<div class="content-body empl-border">
    <div class="empl-full bleu empl-title">Contrat</div>

    <div class="empl-full saumon2 empl-title" style="margin-top: 15px;">
        Type de contrat : <a href="#" id="contrat_type" data-type="select"><?php echo $typeContrat[1]; ?></a>
    </div>
    
    <div>
        <div class="empl-left" style="width: 50%">

            <div class='empl-group'>
                <div class="empl-full">
                    Date d'entrée : <a href='#' id='debut_contrat' data-type='combodate'><?php echo date('d/m/Y'); ?></a>
                </div>
                <div class="empl-full">
                    Date dernier entretien individuel <a class="rhdatetime" href="#" id="entretien" data-type="combodate">Aucun</a>
                    <div class="cancel-icon">
                        <a href="#" class="cancel-date" data-id="entretien" title="Effacer la Date">
                            <img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
                        </a>
                    </div>
                </div>
            </div>

        </div>

        <div class="empl-right" style="width: 49%">
            <div class='empl-group'>
                <div class='empl-full gris' style="visibility: hidden;">
                    Date de départ : <a class="rhdatetime" href='#' id='contrat_fin' data-type='combodate'>Aucun</a>
                    <div class="cancel-icon">
                        <a href="#" class="cancel-date" data-id="contrat_fin" title="Effacer la Date">
                            <img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
                        </a>
                    </div>
                </div>
                <div class='empl-full gris'>
                    Motif départ : <a href='#' id='contrat_motif_depart' data-type='select'>Aucun</a>
                </div>
            </div>
        </div>
    </div>
    
    <div class='clear-auto'> 
        <div class="empl-left" style="width: 50%; margin: 4px 0;">
            <div class='empl-group'style='margin-bottom: 10px; margin-top: -10px;'>
                <div class='empl-full gris' >                    
                    Pièce jointe : 
                    <?php $flagContratFile  = FileManager::EMPLOYE_CONTRAT_FILE ;
                          $fileManager->setFlag($flagContratFile);
                    ?>
                    
                    <?php $idLibelleContrat     = $fileManager->getFlag(). '_libelle' ;
                          $idBtnUplContrat = $fileManager->getFlag() . '-upload'; 
                    ?>
                    
                    <span id="<?php echo $idLibelleContrat; ?>"></span>
                    <a href="#" id="<?php echo $idBtnUplContrat ; ?>" class="btn btn-info btn-small">Télécharger fichier</a>
                </div>
            </div>

        </div>
         <div class="empl-right" style="width: 49%">            

        </div>
    </div>

    <!-- Avenant -->
    <div class="empl-left empl-highlight" style="width: 50%" class='clear-auto'>
	<div class="empl-group" id="posteNew" style="display: Ouie;">
            <div class="empl-full empl-saumon">
                Poste : <a href='#' id='posteNeo' data-type='select' onclick='return false;'></a>
            </div>
            <div class="empl-full empl-saumon">
                Collège : <a href='#' id='collegeNeo' data-type='select'><?php //echo $this->collegeDefault->libelle;  ?></a>
            </div>
            <div class="empl-full empl-saumon">
                Niveau : <a href='#' id='niveauNeo' data-type='select'><?php //echo "Niveau I";  ?></a>
            </div>
            <div class="empl-full empl-saumon">
                Echelon : <a href='#' id='echelonNeo' data-type='select'><?php //echo "Echelon 1";  ?></a>
            </div>
        </div>
    </div>

    <div class="empl-right empl-highlight" style="width: 49%">
        <!-- NOUVELLE AVENANT -->

	<div class="empl-group" id="avenantNew">
            <div class="empl-full empl-jaune">
                Contrat horaire hebdomadaire : <a href='#' id='hebdoX' data-type='text' onclick='return false;'>00.0</a> heure(s)
            </div>
            <div class="empl-full empl-jaune">
                Taux horaire : <a href='#' id='tauxX' data-type='text' onclick='return false;'>00.0</a> €
            </div>
        </div>
    </div>

    <!--    <div class="empl-full"><button class="btn btn-primary" id="avenantAddButton" style="display: Ouie;" onclick="return AddNewAvenant();">Enregistrer</button></div>-->

    <div style="clear: both"></div>

</div>

<div class="empl-center" style="width: 30%">
    <div class="empl-full bleu"><a href='#' onclick='return false;' class='full-link'>Transmission de la fiche à ADEC</a></div>
    <div class="empl-full bleu"><a href='#' onclick='return false;' class='full-link'>Impression Attestation Employeur</a></div>
</div>

<!-- Disponibilité -->

<div class="empl-border" style='margin-top: 15px'>
    <div class="empl-full bleu empl-title" style='margin-bottom: 10px'>Disponibilité</div>

    <div class="list-container">
        <table class="table table-striped list-table">
            <thead>
                <tr>
                    <td></td>
                    <td class='empl-title' style='text-align: center'>Disponibilité</td>
                    <td class='empl-title' style='text-align: center'>Heure d'arrivée</td>
                    <td class='empl-title' style='text-align: center'>Heure de départ</td>
                </tr>
            </thead>
            <tbody>
                <?php  foreach($dayWeek as $d) :  ?>
                    <?php $d_ouv = $d. '_ouverture' ;?>
                    <?php $d_fer = $d. '_fermeture' ;?>
                    <tr>
                        <td class='empl-title' style='text-indent: 15px'><?php echo ucfirst($d);?></td>
                      <td style='text-align: center'>
                          <a class="full-link" href="#" id="<?php echo ($d);?>" data-type="select">
                              <?php echo $site_horaire->$d ? 'Oui' : 'Non' ;?>
                          </a>
                      </td>
                      <td style='text-align: center'>
                          <a class="full-link" href="#" id="<?php echo ($d);?>_entree" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm">
                              <?php if ($site_horaire->$d):                                 
                                        $tm = strtotime($site_horaire->$d_ouv);
                                        $s = sprintf ("%s:%s", date("H", $tm), date("i", $tm) );
                                        
                                      else : 
                                        $s = '00:00' ;
                                      endif ;
                                      echo $s;
                                 ?>
                          </a>
                      </td>
                      <td style='text-align: center'>
                          <a class="full-link" href="#" id="<?php echo ($d);?>_sortie" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm">
                              <?php if ($site_horaire->$d):                                 
                                        $tm = strtotime($site_horaire->$d_fer);
                                        $s = sprintf ("%s:%s", date("H", $tm), date("i", $tm) );
                                        
                                      else : 
                                        $s = '00:00' ;
                                      endif ;
                                      echo $s;
                                 ?>
                          </a>
                      </td>
                  </tr>
                <?php endforeach; ?>
                
                
            </tbody>

        </table>
    </div>

    <div style="clear: both; height: 2em;"></div>

</div>

<div class="content-head">
    <h3>&nbsp;</h3>
    <div class="toolbar">
	<button class='btn btn-success' onclick='return AddNewEmploye();'>Enregistrement de l' employé en cours</button>
	<!--button class='btn btn-inverse' onclick="location.href = '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'index', 'id'		 => $site->id, 'other1'	 => 1)) ?>';">Annuler et revenir à la liste des employés du Site <b><?php echo $site->libelle ?></b></button-->
    </div>
</div>

<div id='avenant-dialog'></div>

<form id="newEmploye" method="post" action="<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'addNew')) ?>">
    <input type="hidden" id="data-matricule" name="matricule" value="0">
    <input type='hidden' id='data-site_id' name='site_id' value='<?php echo $site->id; ?>'>
    <input type="hidden" id="data-nom1" name="nom1" value="">
    <input type="hidden" id="data-nom2" name="nom2" value="">
    <input type="hidden" id="data-prenom" name="prenom" value="">
    <input type="hidden" id="data-telephone" name="telephone" value="">
    <input type="hidden" id="data-email" name="email" value="">
    <input type='hidden' id='data-contrat_debut' name='contrat_debut' value='<?php echo date('Y-m-d'); ?>'>
    <input type='hidden' id='data-contrat_fin' name='contrat_fin' value='0000-00-00'>
    <input type='hidden' id='data-contrat_type' name='contrat_type' value='1'>
    <input type='hidden' id='data-contrat_motif_depart' name='contrat_motif_depart' value='0'>
    <input type='hidden' id='data-avenant_id' name='avenant_id' value='0'>
    <input type='hidden' id='data-civil_id' name='civil_id' value='1'>
    <input type="hidden" id="data-situation" name="situation_id" value="1">
    <input type="hidden" id="data-enfant" name="enfant" value="0">
    <input type="hidden" id="data-date_naissance" name="naissance" value="0000-00-00">
    <input type="hidden" id="data-lieu_naissance" name="naissance_lieu" value="">
    <input type="hidden" id="data-pays_naissance" name="naissance_pays" value="0">
    <input type="hidden" id="data-nationalite" name="nationalite_id" value="0">
    <input type="hidden" id="data-adresse1" name="adresse1" value="">
    <input type="hidden" id="data-adresse2" name="adresse2" value="">
    <input type="hidden" id="data-cp1" name="cp1" value="">
    <input type="hidden" id="data-cp2" name="cp2" value="">
    <input type="hidden" id="data-ville1" name="ville1" value="">
    <input type="hidden" id="data-ville2" name="ville2" value="">
    <input type="hidden" id="data-ville2" name="ville2" value="">
    <input type='hidden' id='data-sejour_id' name='sejour_id' value='0'>
    <input type='hidden' id='data-sejour_fin' name='sejour_fin' value='0000-00-00'>
    <input type='hidden' id='data-sejour_num' name='sejour_num' value=''>
    <input type="hidden" id="data-cpam" name="cpam" value="">
    <input type="hidden" id="data-pole_emploi" name="pole_emploi" value="0">
    <input type="hidden" id="data-mutuelle" name="mutuelle" value="">
    <input type="hidden" id="data-date_effet" name="mutuelle_date_effet" value="0000-00-00">
    
    <?php $flags = array(FileManager::EMPLOYE_RIB_FILE , FileManager::EMPLOYE_CONTRAT_FILE ,  FileManager::EMPLOYE_SEJOUR_NUM_FILE , FileManager::EMPLOYE_CV_FILE  ); ?>
    <?php  foreach ($flags as $flagFile) : ?> 
        <input type='hidden' id='data-<?php echo $flagFile; ?>' name='<?php echo $flagFile; ?>' value=''>
        <input type='hidden' id='data-<?php echo $flagFile; ?>-ext' name='<?php echo $flagFile; ?>_extension' value=''>
    <?php endforeach; ?>
    
    <input type='hidden' id='data-rib_bic' name='rib_bic' value=''>
    <input type='hidden' id='data-rib_iban' name='rib_iban' value=''>
    
    <input type="hidden" id="data-transport_id" name="transport_id" value="">
    <input type='hidden' id='data-actif' name='actif' value='1'>
    <input type='hidden' id='data-code_caisse' name='code_caisse_tcpos' value=''>

    <!-- Avenant -->
    <input type='hidden' id='data-poste_id' name='poste_id' value='0'>
    <input type='hidden' id='data-college' name='college' value='1'>
    <input type='hidden' id='data-niveau' name='niveau' value='1'>
    <input type='hidden' id='data-echelon' name='echelon' value='1'>
    <input type='hidden' id='data-hebdo' name='hebdo' value='0'>
    <input type='hidden' id='data-taux' name='taux' value='0'>
    <input type='hidden' id='data-debut' name='debut' value='<?php echo date('Y-m-d'); ?>'>
    <input type='hidden' id='data-fin_avenant' name='fin' value='0000-00-00'>

    <!-- Disponibilite -->
    <input type='hidden' name='matricule' value='0'>
    <input type='hidden' name='version' value='1'>
    <input type='hidden' name='edition' value='<?php echo date('Y-m-d'); ?>'>
    
    <?php foreach($dayWeek as $d) :  ?>
        <?php $d_ouv = $d. '_ouverture' ;?>
        <?php $d_fer = $d. '_fermeture' ;?>
        <?php if ($site_horaire->$d):     
                $code = \RHX\Model\Object\XRules::Present;
                $tmOuv = strtotime($site_horaire->$d_ouv);
                $tmFer = strtotime($site_horaire->$d_fer);
                
                $sHrOuv = sprintf ("%s:%s", date("H", $tmOuv), date("i", $tmOuv) );
                $sHrFer = sprintf ("%s:%s", date("H", $tmFer), date("i", $tmFer) );

              else : 
                $code = \RHX\Model\Object\XRules::NeTravaillePas;
                $sHrOuv = '00:00' ;
                $sHrFer = '00:00';
              endif ;              
         ?>
        <input type='hidden' id="data-<?php echo $d; ?>" name='<?php echo $d; ?>' value='<?php echo $code ;?>'>
        <input type='hidden' id="data-<?php echo $d; ?>_entree" name='<?php echo $d; ?>_entree' value='<?php echo $sHrOuv ;?>'>
        <input type='hidden' id="data-<?php echo $d; ?>_sortie" name='<?php echo $d; ?>_sortie' value='<?php echo $sHrFer ;?>'>
    <?php endforeach; ?>

    <!-- A completer -->
    <input type="hidden" id="data-vehicule_fonction" name="vehicule" value="">
    <input type="hidden" id="data-immatriculation" name="immatriculation" value="">
    <input type="hidden" id="data-date_visite" name="date_visite" value="0000-00-00">
    <input type="hidden" id="data-num_permis" name="num_permis" value="">
    <input type="hidden" id="data-entretien" name="date_entretien" value="0000-00-00">

    <!-- UPLOADS -->
    <input type="hidden" id="data-photo" name="photo" value="#">
    <input type="hidden" id="data-photo-ext" name="photo_extension" value="">
    
</form>

<script type="text/javascript">
	    // Démarrage
	    $(document).ready(function() {
                var isEmpty = function(selector){
                        return $.trim($(selector).val()) === '';
                    },
                    isFloat = function(val){
                        v = $.trim(val);
                        patFloat = new RegExp(/^[0-9]*[.]{0,1}[0-9]+$/);

                        return patFloat.test(v);                     
                    } ;
                
		$('#etatcivil').editable({
		    title: 'Etat Civil',
		    showbuttons: false,
		    value: 1,
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonetatcivillist')) ?>",
		    validate: function(value) {
			$("#data-civil_id").val(value);
		    }
		});
		$('#site').editable({
		    title: "Site Employeur",
		    showbuttons: false,
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonSiteList')) ?>",
		    validate: function(value) {
			$('#data-site_id').val(value);
		    }
		});
		$('#nom').editable({
		    title: "Nom d'usage",
		    validate: function(value) {
			$('#data-nom1').val(value.toUpperCase());
		    },
		    inputclass: 'uppercase',
		    params: function(params) {
			value = params.value;
			uppercase = value.toUpperCase();
			params.value = uppercase;
			return params;
		    }
		});
		$('#nom2').editable({
		    title: "Nom",
		    validate: function(value) {
			$('#data-nom2').val(value.toUpperCase());
		    },
		    inputclass: 'uppercase',
		    params: function(params) {
			value = params.value;
			uppercase = value.toUpperCase();
			params.value = uppercase;
			return params;
		    }
		});
		$('#prenom').editable({
		    title: "Prénom",
		    validate: function(value) {
			$('#data-prenom').val(value);
		    },
		    inputclass: 'capitalize',
		    params: function(params) {
			value = params.value;
			capitalize = toTitleCase(value);
			params.value = capitalize;
			console.debug(params.value);
			return params;
		    }
		});
		$('#num_mobile').editable({
		    title: "Numéro du téléphone Mobile",
		    validate: function(value) {
			$('#data-telephone').val(value);
		    }
		});
		$('#email').editable({
		    title: "Adresse Email",
		    validate: function(value) {
			$('#data-email').val(value);
		    }
		});
		$('#adresse1').editable({
		    title: "Adresse",
		    validate: function(value) {
			$('#data-adresse1').val(value);
		    }
		});
		$('#adresse2').editable({
		    title: "Adresse",
		    validate: function(value) {
			$('#data-adresse2').val(value);
		    }
		});
		$('#cp1').editable({
		    title: "Code Postal",
		    validate: function(value) {
			cp1 = value;
			$('#data-cp1').val(value);
		    }
		});
		$('#cp2').editable({
		    title: "Code Postal",
		    validate: function(value) {
			cp2 = value;
			$('#data-cp2').val(value);
		    }
		});
		$('#ville1').editable({
		    title: "Ville",
		    validate: function(value) {
			$('#data-ville1').val(value);
		    }
		});
		$('#ville2').editable({
		    title: "Ville",
		    validate: function(value) {
			$('#data-ville2').val(value);
		    }
		});
		$('#num_cpam').editable({
		    title: "Numéro CPAM",
		    validate: function(value) {
			$('#data-cpam').val(value);
		    }
		});
		$('#situation_familiale').editable({
		    title: "Situation familiale",
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonsituationlist')) ?>",
		    validate: function(value) {
			$('#data-situation').val(value);
		    }
		});
		$('#nombre_enfant').editable({
		    title: "Nombre d'enfant",
		    validate: function(value) {
			val = (isNaN(parseInt(value))) ? 0 : parseInt(value);
			val = (val > 99) ? 0 : val;
			$('#data-enfant').val(val);
			setTimeout(function() {
			    $('#nombre_enfant').text(val);
			}, '1000');
		    },
		    tpl: "<input type='number'>"
		});
		$('#num_pole_emploi').editable({
		    title: "Numéro Pole Emploi",
		    validate: function(value) {
			$('#data-pole_emploi').val(value);
		    }
		});
		$('#mutuelle').editable({
		    title: "Mutuelle",
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'mutuelleList')) ?>",
		    validate: function(value) {
			$('#data-mutuelle').val(value);
		    }
		});
		$('#titre_transport').editable({
		    title: "Titre de transport",
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsontransportlist')) ?>",
		    validate: function(value) {
			$('#data-transport_id').val(value);
		    }
		});
		$('#date_effet').editable({
		    title: "Date d'effet",
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    validate: function(value) {
			var val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			$('#data-date_effet').val(val);
		    },
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    },
		    combodate: {
			minYear: 1900,
			maxYear: 2025,
			minuteStep: 1
		    }
		});
		$('#vehicule_fonction').editable({
		    title: "Véhicule de fonction",
		    validate: function(value) {
			$('#data-vehicule_fonction').val(value);
		    }
		});
		$('#immatriculation').editable({
		    title: "Immatriculation du véhicule",
		    validate: function(value) {
			$('#data-immatriculation').val(value);
		    }
		});
		$('#date_visite').editable({
		    title: "Dernière Date de visite Médicale",
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    validate: function(value) {
			var val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			$('#data-date_visite').val(val);
		    },
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    },
		    combodate: {
			minYear: 1900,
			maxYear: 2025,
			minuteStep: 1
		    }
		});
		$('#num_permis').editable({
		    title: "Numéro du Permis de conduire",
		    validate: function(value) {
			num_permis = value;
			$('#data-num_permis').val(value);
		    }
		});
		$('#date_naissance').editable({
		    title: 'Date de naissance',
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    validate: function(value) {
			var val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			age = calcul_age(val);
			//alert(age);
			if (age < 18.0) {
			    showError("L'employé à moins de 18 ans");
			    setTimeout(function() {
				$('#date_naissance').text('Aucun');
				$('#data-date_naissance').val('0000-00-00');
			    }, '1000');
			} else {
			    $('#data-date_naissance').val(val);
			}
		    },
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    },
		    combodate: {
			minYear: <?php echo (int)date('Y') - 100; ?>,
			maxYear: <?php echo (int)date('Y') - 19 ?>,
			minuteStep: 1
		    }
		});
		$('#lieu_naissance').editable({
		    title: "Lieu de naissance",
		    validate: function(value) {
			lieu_naissance = value;
			$('#data-lieu_naissance').val(value);
		    }
		});
		$('#pays_naissance').editable({
		    title: "Pays de naissance",
		    validate: function(value) {
			$('#data-pays_naissance').val(value);
		    }
		});
		$('#nationalite').editable({
		    title: "Nationalité",
		    source: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'getNationaliteList')) ?>',
		    validate: function(value) {
			$('#data-nationalite').val(value);
		    }
		});
                
                $('#num_titre_sejour').editable({
		    title: "Numéro du titre de Séjour",		    
		    validate: function(value) {                        
			$('#data-sejour_num').val($.trim(value));
		    }
		});
                
		$('#titre_sejour').editable({
		    title: "Titre de Séjour",
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'sejourList')) ?>",
		    validate: function(value) {
			titre_sejour = value;
			$('#data-sejour_id').val(value);
		    }
		});
                               
                              
		$('#date_fin_validite_sejour').editable({
		    title: 'Date de Fin de Séjour',
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    validate: function(value) {
			var val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			// supérieur à la date d'aujourd'hui
			if(moment('<?php echo date('Y-m-d'); ?>').isSame(val)){
			    $('#data-sejour_fin').val(val);
			}else{
			    if (isGT('<?php echo date('Y-m-d'); ?>', val)) {
				showError("La date de Fin de validité est antérieur ou égale à la date du Jour");
			    } else {
				$('#data-sejour_fin').val(val);
			    }
			}

		    },
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    },
		    combodate: {
			minYear: <?php echo (int)date('Y') - 100; ?>,
			maxYear: <?php echo (int)date('Y') + 11; ?>,
			minuteStep: 1
		    }
		});
		
                // RIB
                
		$('#rib_upload').fileupload({
		    dataType: 'json',
		    add: function (e, data) {
			data.context = $('<p/>').text('Uploading...').replaceAll($(this));
			data.submit();
		    },
		    done: function (e, data) {
			data.context.text('Upload finished.');
		    },
		    progressall: function (e, data) {
			var progress = parseInt(data.loaded / data.total * 100, 10);
			$('#progress .bar').css('width', progress + '%');
		    }
		});
                
                 $('#rib_iban').editable({
		    title: "IBAN",		    
		    validate: function(value) {
			rib_iban = value;
                        $('#data-rib_iban').val(rib_iban);			
			
		    }
		});
                $('#rib_bic').editable({
		    title: "BIC",		    
		    validate: function(value) {
			rib_bic = value;
                        $('#data-rib_bic').val(rib_bic);			
		    }
		});
                
		// Contrat
		$('#contrat_type').editable({
		    title: 'Type de contrat',
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'contratTypeList')) ?>",
		    validate: function(value) {
			$('#data-contrat_type').val(value);
			$finContrat = $('#contrat_fin');
                        $finContrat.parent().css('visibility', value === '1' ?  'hidden' : 'visible');
                        $finContrat.html('Aucun');
			$('#data-contrat_fin').val('0000-00-00');
		    },
		    inputclass: 'input-large'
		});
		$('#debut_contrat').editable({
		    title: 'Début de Contrat',
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'right',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
                        valContratFin = $("#data-contrat_fin").val();
                        hasDepart = valContratFin !== '0000-00-00';
                        dateDepart = hasDepart? moment(valContratFin) : null;
                        
                        if(hasDepart && moment(val).isAfter(dateDepart)){
                            $('#data-contrat_debut').val('<?php echo date('Y-m-d'); ?>');			   
			    return "La date d'entrée ne doit pas être ultérieure à la date de départ";			    
			}else{
			    $('#data-contrat_debut').val(val);
			    $('#data-debut').val(val);
			}
   
		    },
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    },
		    combodate: {			
			minYear: <?php echo (int)date('Y') - 100; ?>,
			maxYear: <?php echo (int)date('Y') + 11; ?>,
			minuteStep: 1
		    }
		});
		$('#contrat_fin').editable({
		    title: 'Fin de Contrat',
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			debut = $('#data-contrat_debut').val();
			if(isEq(debut, val)){
			     return "La date de début du contrat ne peut pas être la date de fin du contrat" ;

			}else{ 
			    if(isGT(debut, val)){				
				$('#data-contrat_fin').val('0000-00-00');
				$('#data-fin_avenant').val('0000-00-00');
                                return "La date de départ ne doit pas être antérieure à la date d'entrée !" ;
				setTimeout(function() {
				    $('#contrat_fin').text('Aucun');
				}, '1000');
                                
			    }else{
				$('#data-contrat_fin').val(val);
				$('#data-fin_avenant').val(val);
			    }
			}
		    },
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    },
		    combodate: {
			minYear: <?php echo (int)date('Y') - 100; ?>,
			maxYear: <?php echo (int)date('Y') + 11; ?>,
			minuteStep: 1
		    }
		});
		$('#contrat_motif_depart').editable({
		    title: 'Motif de départ',
		    source: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonMotifList')) ?>',
		    validate: function(value) {
			contrat_motif_depart = value;
			$('#data-contrat_motif_depart').val(value);
		    }
		});

		// Disponibilite
		$('#lundi_entree').editable({
		    placement: 'right',
		    format: 'HH:mm',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-lundi_entree').val(val);
		    }
		});
		$('#mardi_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-mardi_entree').val(val);
		    }
		});
		$('#mercredi_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-mercredi_entree').val(val);
		    }
		});
		$('#jeudi_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-jeudi_entree').val(val);
		    }
		});
		$('#vendredi_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-vendredi_entree').val(val);
		    }
		});
		$('#samedi_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-samedi_entree').val(val);
		    }
		});
		$('#dimanche_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-dimanche_entree').val(val);
		    }
		});
		//Sortie
		$('#lundi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-lundi_sortie').val(val);
		    }
		});
		$('#mardi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-mardi_sortie').val(val);
		    }
		});
		$('#mercredi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-mercredi_sortie').val(val);
		    }
		});
		$('#jeudi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-jeudi_sortie').val(val);
		    }
		});
		$('#vendredi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-vendredi_sortie').val(val);
		    }
		});
		$('#samedi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-samedi_sortie').val(val);
		    }
		});
		$('#dimanche_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-dimanche_sortie').val(val);
		    }
		});
		
                <?php foreach($dayWeek as $d) :  ?>
                    $('#<?php echo $d ;?>').editable({
                        title: "Disponibilité",
                        source: [{value: 3, text: 'Non'}, {value: 1, text: 'Oui'}],
                        validate: function(value) {
                            $('#data-<?php echo $d ;?>').val(value);
                            if (value == 3) {
                                $("#<?php echo $d ;?>_entree").text("00:00");
                                $("#<?php echo $d ;?>_sortie").text("00:00");
                                
                                $("#data-<?php echo $d ;?>_entree").val("00:00");                                
                                $("#data-<?php echo $d ;?>_sortie").val("00:00");
                            }
                            if(value == 1 ){                                
                                $("#<?php echo $d ;?>_entree").text("07:00");
                                $("#<?php echo $d ;?>_sortie").text("23:00");
                                
                                $("#data-<?php echo $d ;?>_entree").val("07:00");                                
                                $("#data-<?php echo $d ;?>_sortie").val("23:00");
                            }
                        }
                    });
                <?php endforeach; ?>
                
		// Add Avenant
		addAvenant(false);
		// Code Caisse
		$('#code_caisse').editable({
		    title: "Code Caisse TC POS",
		    validate: function(value) {
			$('#data-code_caisse').val(value);
		    }
		});
		// Entretien Individuel
		$('#entretien').editable({
		    title: "Date de l'entretien individuel",
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    },
		    validate: function(value) {
			var val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			$('#data-entretien').val(value);
		    }
		});
		// Ajouter un diplome
		$('.add-diplome').click(function(e) {
		    e.preventDefault();
		    ajax = $.ajax({
			type: 'post',
			url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'selectDiplome')) ?>',
			data: '&matricule=0'
		    });
		    ajax.done(function(data) {
			$('#dialog1').hide().html(data).fadeIn('fast').dialog({
			    width: 480,
			    height: 340,
			    title: "Sélection des Diplômes",
			    autoOpen: true,
			    modal: true,
			    show: {effect: 'fade', duration: 500},
			    hide: {effect: 'fade', duration: 250},
			    draggable: false
			});
		    });
		    ajax.fail(function() {
			showError("Une erreur est survenue lors du chargement des diplômes !");
		    });
		});
		// Ajouter un Formation
		$('.add-formation').click(function(e) {
		    e.preventDefault();
		    ajax = $.ajax({
			type: 'post',
			url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'selectFormation')) ?>',
			data: '&matricule=0'
		    });
		    ajax.done(function(data) {
			$('#dialog1').hide().html(data).fadeIn('fast').dialog({
			    width: 480,
			    height: 340,
			    title: "Sélection des Formations",
			    autoOpen: true,
			    modal: true,
			    show: {effect: 'fade', duration: 500},
			    hide: {effect: 'fade', duration: 250},
			    draggable: false
			});
		    });
		    ajax.fail(function() {
			showError("Une erreur est survenue lors du chargement des formations !");
		    });
		});

		// RHDateTime
		$('.rhdatetime').each(function() {
		    text = $(this).text();
		    result = isValideDateRH(text);
		    if (!result) {
			$(this).text("Aucun");
		    }
		});

		// Effacer une date
		$('.cancel-date').click(function(e) {
		    e.preventDefault();
		    id = $(this).attr('data-id');
		    $('#' + id).text('Aucun');
		    $('#data-' + id).val('0000-00-00');
		});

		// UPLOAD FICHIER
                <?php $flags = array(FileManager::EMPLOYE_RIB_FILE , FileManager::EMPLOYE_CONTRAT_FILE ,  FileManager::EMPLOYE_SEJOUR_NUM_FILE , FileManager::EMPLOYE_CV_FILE); ?>
                <?php  foreach ($flags as $flagFile) : ?> 
                    $('#<?php echo $flagFile ;?>-upload').click(function(e){
                        e.preventDefault();
                        // affichage d'une fenetre
                        uploadWindow = window.open('<?php echo $this->url('RHX/default', array('controller'	 => 'file', 'action'	 => 'upload', 'id' => '0')) ?>?flag=<?php echo  $flagFile ;?>', 'UploadWindow', 'menubar=no, scrollbars=no, top=100, left=100, width=500, height=400');
                    });
                <?php endforeach; ?>
                
		// Uploader un CV
                /*
		$('#cv-upload').click(function(e){
		    e.preventDefault();
		    uploadWindow = window.open('<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'uploadCv', 'id'		 => '0')) ?>', 'UploadWindow', 'menubar=no, scrollbars=no, top=100, left=100, width=500, height=400');
		});*/

		// Uploader une Photo
		$('#photo-upload').click(function(e){
		    e.preventDefault();
		    uploadWindow = window.open('<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'uploadPhoto', 'id'		 => '0')) ?>', 'UploadWindow', 'menubar=no, scrollbars=no, top=100, left=100, width=500, height=400');
		});
	    });

	    function afficherAvancement(e){
	    if(e.lengthComputable){
		    $('progress').attr({value:e.loaded,max:e.total});
	    }
}

	    /**
	     * Effacer un Truc

	     * @param {type} url
	     * @param {type} pk
	     * @param {type} title
	     * @param {type} prefix
	     * @returns {Boolean} */
	    function deleteSomething(url, pk, title, prefix) {
		if (!url)
		    return false;
		if (!pk)
		    return false;
		if (!title)
		    title = "Voulez-vous effacer ?";
		if (!prefix)
		    prefix = '';
		if (!confirm(title))
		    return false;
		$('#' + prefix + pk).parent().hide('normal');
		$('#form-' + prefix + pk).remove();

		return false;
	    }

	    /**
	     *
	     * @param {string} d
	     * @returns {Boolean}
	     */
	    function isValideDateRH(d) {
		length = d.length;
		if (length > 10) {
		    return false;
		}
		return true;
	    }

	    /**
	     * Sauvegarde
	     * @returns {undefined}
	     */
	    function save()
	    {
		date_naissance = $("#date_naissance").val();
		date_fin_validite_sejour = $("#date_fin_validite_sejour").val();
		date_effet = $("#date_effet").val();

		var data = $('#formData').serialize();
		//data += "&date_naissance=" + date_naissance + "&date_effet=" + date_effet + "&date_fin_sejour=" + date_fin_validite_sejour;
		var ajax = $.ajax({
		    type: 'post',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveedit', 'id'		 => 0)) ?>",
		    data: data
		});
		ajax.success(function() {
		    location.href = "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'index', 'id'		 => $site->id)) ?>";
		});
		ajax.error(function() {
		    showError("Une erreur est survenue");
		});
	    }

	    function dump(obj) {
		var out = '';
		for (var i in obj) {
		    out += i + ": " + obj[i] + "\n";
		}

		alert(out);
	    }

	    function addAvenant(ask)
	    {
		// New Amendemnt
		$('#new-avenant').val(1);
		var annuler = "Cliquer ici pour <a href='#' onclick='return cancelNewAvenant();'>Fermer</a>";
		$('#avenant-message').show('slow').html("<span>Un nouvel avenant sera créer à l'enregistrement des informations en cours</span>. " + annuler);

		// Masquage des Edition, Affichage des Nouveaux
		$('#posteNew').show('normal');
		// Rendre éditable
		$('#posteNeo').editable({
		    title: "Edition du Nouveau Poste",
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonpostelist')) ?>",
		    validate: function(value) {
			$("#data-poste_id").val(value);
			poste = value;
			ajax = $.ajax({
			    type: 'post',
			    url : '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'getPosteInfo')) ?>',
			    data: '&id=' + poste
			});
			ajax.done(function(result){
			    info = result.info;
			    $('#collegeNeo').text(info.college);
			    $('#niveauNeo').text(info.niveau);
			    $('#echelonNeo').text(info.echelon);
			    // changement des données
			    $('#data-niveau').val(info.niveau_value);
			    $('#data-echelon').val(info.echelon_value);
			    $('#data-college').val(info.college_value);
			});
		    }
		});
		$('#niveauNeo').editable({
		    title: "Edition du NIveau",
		    source: '<?php echo json_encode($niveau); ?>',
		    validate: function(value) {
			$('#data-niveau').val(value);
		    }
		});
		$('#echelonNeo').editable({
		    title: "Edition de l'échelon",
		    source: '<?php echo json_encode($echelon); ?>',
		    validate: function(value) {
			$('#data-echelon').val(value);
		    }
		});
		$("#collegeNeo").editable({
		    title: "Edition du collège",
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'collegeList')); ?>",
		    validate: function(value) {
			$('#data-college').val(value);
		    }
		});
		$('#avenantNew').show('normal');
		// Rendre éditable
		$('#hebdoX').editable({
		    title: "Modification de l'Heure Hedbomadaire",
		    validate: function(value) {
			$('#data-hebdo').val(value);
		    },
                    tpl: "<input type='text' onKeyPress='validateNumber(event);' onclick='select();' onmouseover='select();'>",
		    /*tpl: "<input type='text' onclick='select();'>"*/
		});
		$('#tauxX').editable({
		    title: "Modification du Taux Horaire",
		    validate: function(value) {
			$('#data-taux').val(value);
		    },
                    tpl: "<input type='text' onKeyPress='validateNumber(event);' onclick='select();' onmouseover='select();'>",
		    /*tpl: "<input type='text' onclick='select();'>"*/
		});
		$('#debutX').editable({
		    title: "Date de Début de l'Avenant",
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    validate: function(value) {
			var val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			$('#data-debut').val(val);
		    },
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    }
		});
		$('#finX').editable({
		    title: "Date de Fin de l'Avenant",
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    validate: function(value) {
			var val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			$('#data-finX').val(val);
		    },
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    }
		});

		// Changement de couleur
		$('.empl-saumon').removeClass('empl-saumon').addClass('saumon');
		$('.empl-jaune').removeClass('empl-jaune').addClass('jaune');
		$('.empl-gris').removeClass('empl-gris').addClass('gris');

		return false;
	    }

	    function cancelNewAvenant()
	    {
		$('#new-avenant').val(0);
		$('#avenant-message').html('<span></span>');

		return false;
	    }

	    function avenantHistory(employeId)
	    {
		var url = "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'avenant')) ?>/" + employeId;
		var ajax = $.ajax({
		    type: 'post',
		    url: url
		});
		ajax.success(function(data) {
		    $('#avenant-dialog').html(data).dialog({
			title: "Historique des avenants pour <?php echo $name ?>",
			width: 800,
			height: 600,
			autoOpen: true,
			modal: true,
			show: {effect: 'fade', duration: 700},
			hide: {effect: 'fade', duration: 700},
			draggable: false
		    });
		});
		ajax.error(function() {
		    showError("Ne peut pas afficher l'historique");
		});

		return false;
	    }

	    function avenantDetails(avenantId, title)
	    {
		var url = "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'avenantdetails')) ?>/" + avenantId;
		var ajax = $.ajax({
		    type: 'post',
		    url: url,
		    data: '&title=' + encodeURI(title)
		});
		ajax.success(function(data) {
		    $('#avenant-dialog').html(data).dialog({
			title: title,
			width: 480,
			height: 480,
			autoOpen: true,
			modal: true,
			show: {effect: 'fade', duration: 700},
			hide: {effect: 'fade', duration: 700},
			draggable: false
		    });
		});
		ajax.error(function() {
		    alert("Ne peut pas afficher l'historique");
		});

		return false;
	    }

	    function editAvenant()
	    {
		// It makes the avenant fields editable
		var conf = confirm("Voulez-vous Editer l'Avenant en cours ?");
		if (!conf)
		    return false;

		makeEditable();

		return false;
	    }

	    function makeEditable()
	    {
		// Changement de couleur
		$('.empl-saumon').removeClass('empl-saumon').addClass('saumon');
		$('.empl-jaune').removeClass('empl-jaune').addClass('jaune');
		$('.empl-gris').removeClass('empl-gris').addClass('gris');
		// Highlight
		setTimeout(function() {
		    $('.empl-highlight').effect('highlight', 'slow');
		}, 1000);
		// Masquage du Bouton Ajouter
		$('#avenantNewButton').hide(2500);

		$('#poste').editable({
		    title: 'Poste',
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonpostelist')) ?>",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>",
		    validate: function(value) {
			poste = value;
			$('#data-poste_id').val(value);
		    }
		});
		$('#horaire_hebdo').editable({
		    title: 'Horaire Hebdomadaire',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>",
		    validate: function(value) {
			horaire_hebdo = value;
			$('#data-horaire_hebdo').val(value);
		    }
		});
		$('#horaire_taux').editable({
		    title: 'Taux Horaire',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>",
		    validate: function(value) {
			horaire_taux = value;
			$('#data-horaire_taux').val(value);
		    }
		});
		$('#avenant_debut').editable({
		    title: "Date de début de l'Avenant",
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantStringData')); ?>",
		    validate: function(value) {
			var val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			$('#data-debut_avenant').val(val);
		    },
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    }
		});
		$('#avenant_fin').editable({
		    title: "Date de fin de l'Avenant",
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantStringData')); ?>",
		    validate: function(value) {
			var val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			$('#data-fin_avenant').val(val);
		    },
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    }
		});
	    }

	    function AddNewAvenant() {
		ajax = $.ajax({
		    type: 'post',
		    url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'addNewAvenant')) ?>',
		    data: $('#avenantNewForm').serialize()
		});
		ajax.success(function() {
		    location.reload();
		});
		ajax.error(function() {
		    location.reload();
		});
	    }

	    function AddNewEmploye() {
		$('.errorSaisie').removeClass('errorSaisie');
		err = false;
		errMsg = new Array();
		errCount = 0;
		nom = $('#data-nom1').val();
		prenom = $('#data-prenom').val();
		debut = $('#data-contrat_debut').val();
		fin = $('#data-contrat_fin').val();
                posteNeo = $('#data-poste_id').val();
		if (nom.length < 2) {
		    err = true;
		    errMsg[errCount++] = "Le Nom est vide ou trop court";
		    $('#nom').parent().addClass('errorSaisie');
		}
		if (prenom.length < 2) {
		    err = true;
		    errMsg[errCount++] = "Le Prénom est vide ou trop court";
		    $('#prenom').parent().addClass('errorSaisie');
		}
		if (debut === '0000-00-00' || debut.length < 8) {
		    err = true;
		    errMsg[errCount++] = "La date de début du contrat est invalide";
		    $('#debut_contrat').parent().addClass('errorSaisie');
		}
		if (fin === '0000-00-00' || fin.length < 8) {
		    typeContrat = parseInt($('#data-contrat_type').val());
		    if (typeContrat === 0 || typeContrat === 1) {
			// CDI
			// On ne fait pas la vérification
		    } else {
			err = true;
			errMsg[errCount++] = "La date de fin du contrat est invalide";
			$('#contrat_fin').parent().addClass('errorSaisie');
		    }
		}
                if(!parseInt(posteNeo)){
                    err = true;
                    errMsg[errCount++] = "Aucun poste n' est selectionné !";
                }
                    
		if (err) {
		    msg = "<ol>";
		    for (i = 0; i < errCount; i++) {
			msg += '<li>' + errMsg[i] + "</li>";
		    }
		    msg += '</ol>';
		    showError(msg);

		    return false;
		}
		// Submit
		$('#newEmploye').submit();
		return false;
	    }
	    //Capitalize
	    function toTitleCase(str) {
		return str.replace(/\w\S*/g, function(txt) {
		    return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
		});
	    }

	    /**
	     *
	     * @param {type} date
	     * @param {type} min
	     * @param {type} max
	     * @returns {Boolean}
	     */
	    function isBetween(date, min, max) {
		if (moment(date).isAfter(min) && moment(date).isBefore(max))
		    return true;
		else
		    return false;
	    }

	    function calculAge(dateNaissance) {
		if (!dateNaissance)
		    return 0;
		naissance = moment(dateNaissance);
		maintenant = moment();
		maintenant.subtract('year', naissance.year());
		return maintenant.year();
	    }

</script>
<style type="text/css">
    #nom, #nom2{
	text-transform: uppercase;
    }
    .uppercase{
	text-transform: uppercase;
    }
    .capitalize{
	text-transform: capitalize;
    }
    .cancel-icon{
	position: absolute;
	top: 1px;
	right: 4px;
    }
    .errorSaisie{
	box-shadow: 0px 0px 3px 2px #ff3300;
	border: solid 1px #cc0000;
    }
    .bar {
	height: 18px;
	background: green;
    }
    #photo{
	display: block;
	margin: auto;
    }
</style>